/*
 * matrix.h
 *
 * Esercitazione 1 dell'Insegnamento di Robotica.
 * Laurea Specialistica in Ingegneria Informatica,
 * Universita' degli Studi di Parma
 * Responsabile: Dario Lodi Rizzini
 */
#ifndef MATRIX_H
#define MATRIX_H

#include <iostream>
#include <fstream>
#include <limits>
#include <cassert>

// ----------------------------------------------------------------------
//  SIMPLE VECTOR TYPE
// ----------------------------------------------------------------------

class Vector
{
public:
  Vector(int size);
  
  ~Vector(); 
  
  int size() const;
  
  double value(int i) const;
   
  double& value(int i);
    
  double& operator()(int i);
  
  void assign(double v);
  
  void assign(const Vector& v);
  
  void sum(const Vector& v) const;
  
  double prod(const Vector& v) const;
  
  void prod(double s);
  
  double norm2() const;
  
  void normalize();
  
  void swap(Vector& v);

private:
  double* values_;
  int size_;
};


// ----------------------------------------------------------------------
//  SIMPLE SYMMETRIC MATRIX TYPE
// ----------------------------------------------------------------------

class SymmetricMatrix
{
public:
  SymmetricMatrix(int size);
  
  ~SymmetricMatrix(); 
  
  int size() const;
  
  double value(int i,int j) const;
  
  double& value(int i,int j);
  
  double& operator()(int i,int j);
  
  double getMax() const;
  
  double getMin() const;
  
  void prod(Vector& r,const Vector& v);
  
  // It uses Lanczos algorithm to compute main eigenvector.
  // Bugged! Do not use it
  void computeMainEigenVectorLanczos(Vector& v,int nstep);
  
  // It uses Power method algorithm to compute main eigenvector.
  // It can be used only for symmetric positive definite matrices.
  double computeMainEigenVectorPower(Vector& v,int nstep);    
  
  void savePgm(const char* filename) const;

private:
  double* values_;
  int size_;
};

#endif

